package gatperdut.chato.core.messaging.replies;

import gatperdut.chato.core.ChatoServer;
import gatperdut.chato.core.messaging.grammar.messinfo.ListItemsInRoomInfo;
import gatperdut.chato.core.room.RoomController;
import gatperdut.chato.model.Chato.Item.Item;

import org.json.simple.JSONArray;

public class ListItemsInRoomReply extends Reply {

    public ListItemsInRoomReply( ListItemsInRoomInfo listItemsInRoomInfo, ChatoServer chatoServer ) {
        super( listItemsInRoomInfo, chatoServer );
    }

    @Override
    public String send() {
        RoomController roomController = getChatoServer().getRoomHandler().findRoomControllerByCDOID( getMessageInfo().getRoomID() );
        Item[] allItems = getItemsPackager().toArray( roomController.getInventoryController().getInventory().getItems().toArray() );
        JSONArray allItemsJA = getItemsPackager().packageAll( allItems );
        return allItemsJA.toJSONString();
    }

    @Override
    public ListItemsInRoomInfo getMessageInfo() {
        return (ListItemsInRoomInfo) super.getMessageInfo();
    }

}
